package com.gitee.zycra.union.api.service;

import com.gitee.zycra.jdbc.model.PageResult;
import com.gitee.zycra.union.api.common.bo.CommonResult;
import com.gitee.zycra.union.api.common.bo.PageQuery;
import com.gitee.zycra.union.api.common.param.AddInterfaceParam;
import com.gitee.zycra.union.api.common.param.PageQueryInterfaceParam;
import com.gitee.zycra.union.api.common.param.UpdateInterfaceParam;
import com.gitee.zycra.union.api.common.vo.InterfaceVO;
import com.gitee.zycra.union.api.manager.ApiInterfaceManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zycra
 */
@Slf4j
@Service
public class ApiInterfaceService {

    @Autowired
    private ApiInterfaceManager apiInterfaceManager;

    /**
     * 添加接口
     *
     * @param addInterfaceParam 添加参数
     * @return 添加结果
     */
    public CommonResult<String> addInterface(AddInterfaceParam addInterfaceParam) {
        apiInterfaceManager.addInterface(addInterfaceParam);
        return CommonResult.success();
    }

    /**
     * 更新接口
     *
     * @param updateInterfaceParam 更新参数
     * @return 更新结果
     */
    public CommonResult<String> updateInterface(UpdateInterfaceParam updateInterfaceParam) {
        apiInterfaceManager.updateInterface(updateInterfaceParam);
        return CommonResult.success();
    }

    /**
     * 删除接口
     *
     * @param id 接口ID
     * @return 删除结果
     */
    public CommonResult<String> deleteInterface(Long id) {
        apiInterfaceManager.deleteInterface(id);
        return CommonResult.success();
    }

    /**
     * 查询接口
     *
     * @param pageQuery 查询参数
     * @return 查询结果
     */
    public CommonResult<PageResult<InterfaceVO>> pageQueryInterface(PageQuery<PageQueryInterfaceParam> pageQuery) {
        return CommonResult.success(apiInterfaceManager.pageQueryInterface(pageQuery));
    }
}
